﻿using System;
using System.Windows.Forms;
using System.Windows.Forms.Calendar;
using SmartHealthCareDbLayer;
using System.Linq;

namespace SmartHealthCare.Frm
{
    public partial class FrmConsultaMedicaItem : Form
    {
        public FrmConsultaMedicaItem(ref CalendarItem item, FrmConsultaMedica.AddItemConsulta addItemConsulta)
        {
            InitializeComponent();
            _item = item;
            _addItemConsulta = addItemConsulta;
            Mostrar(_item);
        }

        private void Mostrar(CalendarItem item)
        {
            _txtNota.Text = item.Text;
            _cbCliente.SelectedItem = item.Tag as Clientes;
        }

        private  System.Windows.Forms.Calendar.CalendarItem _item;
        private readonly FrmConsultaMedica.AddItemConsulta _addItemConsulta;

        private void BntAceptarClick(object sender, EventArgs e)
        {
            _item.Text = _txtNota.Text.Trim();
            _item.Tag = _cbCliente.SelectedItem as Clientes;
            _addItemConsulta(ref _item);
            Close();
        }

        private void FrmConsultaMedicaItem_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            _cbCliente.DataSource = ModelSingle.Instance.Clientes.ToList();
            _cbCliente.ValueMember = "IdCliente";
            _cbCliente.DisplayMember = "Nombre";

            //
            _cbEstadoConsulta.DataSource = ModelSingle.Instance.EstadoConsulta.ToList();
            _cbEstadoConsulta.DisplayMember = "Decripcion";
            _cbEstadoConsulta.ValueMember = "IdEstado";

        }

        private void FrmConsultaMedicaItem_Leave(object sender, EventArgs e)
        {
            Close();
        }
    }
}
